package com.example.dayu521.sg_oss.util;

import com.example.dayu521.sg_oss.conf.RedisC;
import org.springframework.data.redis.hash.HashMapper;
import org.springframework.data.redis.hash.Jackson2HashMapper;

import java.util.Map;

//https://docs.spring.io/spring-data/redis/docs/current/reference/html/#redis.hashmappers.mappers
public class RedisHashBe {
    //应该是线程安全的把
    private static final Jackson2HashMapper mapper = new Jackson2HashMapper( RedisC.getObjectMapper(),false);
    static {

    }

    public static <T>  Map<String, Object> Obj2Map(T obj) {
        return mapper.toHash(obj);
    }

    public static <T> T map2Obj(Map<String, Object> map){
        return (T)mapper.fromHash(map);
    }
}
